/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 */
var FindElements = function (root) {
    root.val = 0
    const middleTraverse = (treeNode) => {
        let val = 2 * treeNode.val
        if (treeNode.left) {
            treeNode.left = val + 1
            middleTraverse(treeNode.left)
        }
        if (treeNode.right) {
            treeNode.right = val + 2
            middleTraverse(treeNode.right)
        }
    }
    middleTraverse(root)
};

/** 
 * @param {number} target
 * @return {boolean}
 */
FindElements.prototype.find = function (target) {
    const queue = []
    const arr = []
    queue.push(this.root)
    while (queue.length > 0) {
        let node = queue.shift()
        if(node) arr.push(node.val)
        else arr.push(-1)
        if(node.left || node.right) {
            queue.push(node.left)
            queue.push(node.right)
        }
    }
    return false
};

/**
 * Your FindElements object will be instantiated and called as such:
 * var obj = new FindElements(root)
 * var param_1 = obj.find(target)
 */